/**
 * Created by Administrator on 2016/7/9.
 */


    $(function(){
        goToTop.goToTop();

        $('body').on({
            'mouseenter':function(){

                $('.wechatimg').stop().slideDown();
                //$('.wechatimg').css('display','block');
            },
            'mouseleave':function(){
                $('.wechatimg').stop().slideUp();

                //$('.wechatimg').css('display','none');
            }
        },'.footer-attention .wechat a');


    })

/********************
 * 取窗口滚动条高度,取窗口可视范围的高度,取文档内容实际高度 jiph 160709
 *******************/
var getDocumentHeights={

    /********************
     * 取窗口滚动条高度
     ******************/
    getScrollTop:function(){
        var scrollTop=0;
        if(document.documentElement&&document.documentElement.scrollTop)
        {
            scrollTop=document.documentElement.scrollTop;
        }
        else if(document.body)
        {
            scrollTop=document.body.scrollTop;
        }
        return scrollTop;
    },
    /********************
     * 取窗口可视范围的高度
     *******************/
    getClientHeight:function(){
        var clientHeight=0;
        if(document.body.clientHeight&&document.documentElement.clientHeight)
        {
            var clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
        }
        else
        {
            var clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
        }
        return clientHeight;
    },
    /********************
     * 取文档内容实际高度
     *******************/
    getScrollHeight:function(){
        return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
    }

}


/*******************************************************************************
 * 功能：回到头部
 * 作者：jiph
 * 时间：2016-02-25
 ******************************************************************************/
var goToTop = {
    addStyle:function(configCss){
        if ((/msie (\d+)/i.test(navigator.userAgent) && !window.opera) ? parseInt(RegExp.jQuery1) : 0) {
            var t = document.createStyleSheet();
            t.cssText = configCss;
        }else{
            var r = document.createElement("style");
            r.setAttribute("type", "text/css");
            document.getElementsByTagName('head')[0].appendChild(r);
            if(r.styleSheet){
                r.styleSheet.cssText = configCss;
            }else{
                r.appendChild(document.createTextNode(configCss));
            }
        }
    },
    createHTML:function(configHTML,configClass,configId){
        if(!this.box){
            this.box = document.createElement("div");
            this.box.innerHTML = configHTML;
            document.body.appendChild(this.box);
            if(configId){this.box.id = configId;};
            if(configClass){this.box.className = configClass;};
        }
        return this;
    },
    goToTop: function(opt,flatw) {

        var height=$(document).height();
        if(height>2000)
        {
            var opt = opt || {};
            var botNum = opt.botNum || '15px';
            var gotoHtml = '<a class="backBtn" href="javascript:void(0)"></a>';
            this.createHTML(gotoHtml, "backArea", "backArea");
            this.goBackTop(flatw);
        }

        _s();
        $(window).scroll(_s);
        function _s() {
            var winScrollTop = $(window).scrollTop();
            if (winScrollTop < 350)
            {
                $("#backArea").hide();
            }
            else
            {
                $("#backArea").show();

            }

        }
        var otherRoomPart = $('.footer-box').offset().top;//底部
        var footerheight=$('.footer-box').height();
        $(window).scroll(function() {
            var scrollTop = $(document).scrollTop();
            // if ((scrollTop+footerheight+150 >= otherRoomPart)||(scrollTop+300>=$(document).height()-$(window).height())) {
            //     $('#backArea').stop().animate({'bottom':'536px'},10);
            //     $('#webim-dom').stop().animate({'bottom':'428px'},10);
            // }
            // else {
            //     $('#backArea').css('bottom','155px');
            //     $('#webim-dom').css('bottom','46px');
            //
            // }

            $('#backArea').css('bottom','66px');
            $('#webim-dom').css('bottom','170px');
        })




    },
    goBackTop: function(flatw) {
        var gotoCss = ".backArea{bottom:16px;right:5px;z-index:1003;display:block;width:33px;height:33px;position:fixed}.backArea .backBtn{display:inline-block;width:33px;height:33px;font-size:33px;color:#fff;background:#999;border-radius: 4px 0 0 4px;-webkit-border-radius: 4px 0 0 4px;-moz-border-radius: 4px 0 0 4px; -ms-border-radius:4px 0 0 4px;}";
        this.addStyle(gotoCss);
        $("#backArea .backBtn").click(function(){
            $("html,body").animate({
                scrollTop: 0
            }, 300);
            return false;
        });


    }
}



var hidefixedBox={
    hideBox:function(){
        var iTop = $('.footer-box').offset().top+60;

        window.onresize = window.onscroll = function(){
            try{
                var wiTop = (document.documentElement.scrollTop || document.body.scrollTop);
                if(wiTop >= iTop ){
                    $('#webim-dom').css('display','none');
                    $('body .backArea').css('display','none');
                }else{

                    $('#webim-dom').css('display','block');
                    $('body .backArea').css('display','block');
                }
            }
            catch(e)
            {
                console.log(e);
            }


        }
    }
}



/**自定义 搜索框
 * opt 包含要绑定的input，搜索项的box
 * ***/

var defineSelect = {

    init: function(opt,fn) {
        if(opt.input.length==0||opt.box.length==0)
            return;


        opt.input.parent().click(function(){


            if(opt.box.css('display')=='none')
            {
                if(opt.noanimat)
                    opt.box.show();
                else
                   opt.box.stop().slideDown();
            }
            else {
                if(opt.noanimat)
                    opt.box.hide();
                else
                    opt.box.stop().slideUp();

            }
        });

        opt.box.on('click','li',function(){
            var $this=$(this);
            opt.input.val($this.html()).attr('numvalue',$this.attr('value'));
            if(fn)
                return fn();
        })
        $('body').on('click',function(e){
            if($(e.target).hasClass('defineselectinputbox') || $(e.target).parents('.defineselectinputbox').length>0)
                return;
            if(opt.box.css('display')=='block')
                opt.box.stop().slideUp();

        })
    }
}





